<template>
  <el-container class="home-container">
    <!-- 页面头部区域 -->
    <el-header>
      <div>
        <span class="logo-text">后台管理系统</span>
      </div>
     <el-button type="info" @click="test">测试123</el-button>
      <el-button type="info" @click="logout">退出</el-button>
    </el-header>
    <!-- 页面主体 -->
    <el-container>
      <!-- 页面左侧边栏 -->
      <el-aside width="200px">
        <!-- 侧边栏菜单区域 -->
        <el-menu background-color="#333644" text-color="#fff" active-text-color="#ffd04b">
          <!-- 一级菜单 -->
          <el-submenu :index="item.id+''" v-for="item in itemList" :key="item.id">
            <!-- 一级菜单的模板区域 -->
            <template slot="title">
              <!-- 图标 -->
              <i class="el-icon-location"></i>
              <!-- 文本 -->
              <span>{{item.title}}</span>
            </template>
            <!-- 二级菜单 -->
            <el-menu-item :index="child.id+''" v-for="child in item.childPermissionList" :key="child.id">
              <template slot="title">
                <!-- 图标 -->
                <i class="el-icon-location"></i>
                <!-- 文本 -->
                <span>{{child.title}}</span>
              </template>
            </el-menu-item>
          </el-submenu>
        </el-menu>
      </el-aside>
      <!-- 页面右侧主体区域 -->
      <el-container>
        <el-main>Main</el-main>
        <!-- 页面页脚区域 -->
        <el-footer>Footer</el-footer>
      </el-container>
    </el-container>
  </el-container>
</template>
<script>
export default {
  // 生命周期函数
  created () {
    this.getMenuList()
  },
  data () {
    return {
      itemList: []
    }
  },
  methods: {
    logout () {
      window.sessionStorage.clear()
      this.$router.push('/login')
    },
    test () {
      this.$request.post('/admin/home')
    },
    async getMenuList () {
      // 获取所有菜单
      const result = await this.$request.get('/admin/menuList')
      console.log(result)
      if (result.code !== 200) {
        return this.$message.error(result.msg)
      }
      this.itemList = result.permissionList
      console.log(this.itemList)
    }
  }
}
</script>
<style lang="less" scoped>
  .el-header {
    background-color: #373c40;
    display: flex;
    justify-content: space-between;
    align-items: center;
    color: #fff;
    font-size: 20px;

    >div {
      display: flex;
      align-items: center;
    }
  }

  .el-aside {
    background-color: #333644;
  }

  .el-main {
    background-color: #eaedf1;
  }

  .el-footer {
    background-color: #17212a;
  }

  .home-container {
    height: 100%;
  }
</style>
